first implementation of kernel-based distance