What could be the cause of these erratic and extremely high ping times between two MacBooks over wifi?

It's wifi - there may be nothing to "fix" if you have lots of other people using wifi, especially on the same channel as you. Wifi is a shared resource. Cabled connections are not (and always better if you have a choice).

Are you in a house or apartment? How many of your neighbors are using wifi? Are you using channel 1, 6 or 11 on 2GHz? More importantly are your neighbors also using the same channel? Do NOT use anything other than 1, 6 or 11 on 2GHz bands - all the other channels will overlap with 1 and 6 or 6 and 11. 5GHz channels do not overlap in the same way so it's less of a deal with 5GHz.

A quick way to see who is around you and what channels they are using is to use an app like http://www.netspotapp.com to do a quick survey and see what is going on around you.

The more use of wifi around you, the more the ping times are going to vary. If you don't have neighbors close by, how many other devices do you have on wifi? It all adds up...