I found that the difference is sometimes ~3, sometimes ~2 or ~4 Hz. Why isn't it constant? Would it be better if it was constant?
It seems to me that this is a rather difficult question and maybe the only real answer is „cause it happens to be this way”.
It breaks down to: If you want to partition the frequency range into octaves and each of this intervals into a constant number (12) of pitches (halftones) then constant ratio instead of constant difference is simply a necessity.
As the comments already pointed out musical pitch happens to be geometric rather than arithmetic. That is e.g. if one A has a frequency of 440 Hz the A one octave higher has a pitch of 880 Hz = 440 Hz * 2. The A one more octave higher has a frequency of 880 Hz * 2 = 1760 Hz. If the frequency/pitch relation would be linear you could expect it to have a frequency of 880 Hz + 440 Hz = 1320 Hz which is not the way how it is organised.
If you accept this relation for octaves than the idea of "equal frequency differences" is obviously not compatible with the idea to have the same number of halftone steps in each octave.
Why octaves then? And why do they double the frequency?
One line of reasoning is the anatomy of the ear. The cochlea is constructed in a way that octaves lead to a similar neural stimulus.
Another line of reasoning is that tones an octave away have the highest degree of similarity:
Because they have of all possible frequency combinations the best alignment. That is the time after which the pattern formed by the tone at f1 and the tone at 2*f1 has the lowest period. It repeats after 1 wavelength of the tone with lower frequency.
f1 and 1.5 times f1 e.g. repeat after 2 wavelengths of the tone with the lower frequency.
Which happens the be the reason why the cochlea will give a neural stimulus of maximum similarity for two tones an octave away :-)
For a “perfect unison” it is always better if there is no difference between the two frequencies. If the two frequencies are different by 2 Hz, you will hear two “beats” per second due to the interference between the wave frequencies. A difference of 4 Hz will sound like four beats per second. These sound “out of tune”. A musician who is playing out of tune is trained to quickly adjust (fingering, embouchure, slide position) in order to eliminate the interference beat.
Being able to reproduce absolutely stable frequencies is the purview of electronic music synthesis. One common musical device requires the musician to modulate the frequency of a note like a wave. It is called “vibrato” and results in a more beautiful music tone— even though the frequency is very unstable!
In music, it is very common to express the tuning of a pitch in “cents”, where one cent is a hundredth part of the distance between semitones in 12-tone equal temperament. In university we learned a difference of only 3¢ is audible to most people. If someone says you are playing 2¢ sharp, a good reaction would be “oh really?”, whereas if you were 8¢ off an adjustment would absolutely be required.
There are other scales with more or less than 12 equal semitones per octave. Some scales are logarithmic, like equal temperament is, some are rational (based on frequency ratios) for example scales based on just intonation; Harry Partch’s 43-tone per octave scale https://en.m.wikipedia.org/wiki/Harry_Partch's_43-tone_scale or Dean Drummond’s 31-tone subset.