A Randomized Approximate Nearest Neighbors Algorithm: Theory and Applications