In the method ImageStatisticsCalculator::InternalCalculateStatisticsMasked the itk::MinimumMaximumImageFilter is used to get the index values for min and max. This filter only determines the min and max of an input image, without a mask (so min and max of the complete image).
To be able to get the min and max index values in dependence to the mask an image is created (using the itk::MaskImageFilter) where the values outside the segmentation are set to a value which is between the min and max value:
outsideValue = (min + max)/2
In the case where min and max are the same this would lead to an image where ALL voxel values are the same and the first index is taken. This then would be wrong!
The whole approach is in my opinion not very nice and hard to understand when first looking at it. The itk::LabelStatisticsImageFilter used for the actual statistics calculation unfortunately does not provide the index for the max and min values. This should be easily changeable in the itk::LabelStatisticsImageFilter (I haven't looked at the actual code of the filter yet) and the workaround implemented here is way to complicated. Also this would save time because the statistics have already been calculated and it seems like a waste to create another image and calculate again the max and min values just to get the index values.