You really don't want to rely on the physical inertia of the motor to average the speed,
because that means the current in the windings could have a massive AC component at
the "PWM" frequency, and large copper and iron losses result from this.
You want the PWM frequency to be high enough that the inductance of the windings is
limiting the current variation substantially (an order of magnitude less than the full
load current would be good). In this situation the iron and copper losses are greatly
reduced from the AC component (which is now a relatively small ripple current).
Another factor affecting the PWM frequency is resonance and audible sound from
the windings - taking the PWM frequency up into the ultrasonic range will reduce
Really high PWM frequencies give larger switching losses and EMI issues, so there is
a balance to be found.
I've no idea why they chose the PWM frequencies they did, seems low for
small motors and for LED dimming. Common motor PWM frequencies are 4kHz,
8kHz, 16kHz etc. Note that timer0 serves both to maintain the millis() and micros()
time on the Arduino as well as provide PWM for pins 5 and 6.