Refactor sort/$near distance stuff

Instead of having a semi-implicit dependency on the cursor, specify
distances explicitly when "instantiating" the comparator.

The next refactoring will remove _distance from cursor entirely.