Using a nested function will allow you to share variables without having to resort to evalin. As for your actual problem: you could switch to cellfun, or set the values that are false in your ROI to NaN and adapt your function accordingly. Another option is to use nested functions to share variables, and use an index array.
function B=foo
IM=rand(200,200);
Mask=rand(size(IM))<0.2;
indexArray=reshape(1:numel(IM),size(IM));
fun = @(block_struct) bar(block_struct.data);
B = blockproc(indexArray,[20 20],fun);
function out=bar(ind)
partIM=IM(ind);
partMask=Mask(ind);
%do something
out=max(partIM(partMask));
end
end