fixed iteration-erase bug in ApplyThreshold