Model-Based Visual Planning with Self-Supervised Functional Distances