Fix bug in mask stack masking.

Also only use sampleindices for topographic correction if image is sufficiently large.