cache pairwise frame costs as well as distances