New algorithm for detectRect

Should be faster if the number of points is large