moving sorting out of main imgproc function to getBoundingRects function