The level of the companion or familiar is determined by the number of levels in the appropriate class that the caster/druid/ranger has. You can switch whenever you level up in the class that has the familiar/companion. For example, you could switch out your, say, 12 level panther when you leveled up at level 13, and if you then took a raven, it would be the level 13 equivalent, not the level 12 equivalent or a level 1 familiar or anything.
It's worth noting that in cases of multiclassing, the level of the familiar/compaion again directly corresponds only to the number of levels in the relevant class. A wizard/ranger who had 10 levels of ranger and 5 levels of wizard could have an animal companion equivalent to that of a 10th level ranger and a familiar equivalent to that of a 5th level wizard, but would not get a 15th level companion or familiar.