Update the dtw algorithm to use a DMat instead of a temporary function.