added optional parameter to control number of recursions in recursive thresholding