improved algorithm for checkOverlappingContours()