The mechanics are rule based.

 1. If you have only one hero. He gains experience for the creep killed anywhere he is on the map.
 2. If you have multiple heroes. A hero gains experience when he or any unit under his "command" kills a hostile unit. If multiple heroes are commanding a unit that makes a kill, then the XP is split evenly.
 3. If no hero "commands" the unit that makes the kill, then all heroes, share the XP.

So, now we know which hero will get the XP. But when the hero kills a creep, you get a percentage of the XP ( that he would have received had the hostile unit not been a creep )  depending on your hero level. So level 1 hero -> 80%, level 2 -> 70%, level 3 -> 62%, level 4 -> 55% and level 5 -> 0%. 

Hence, if you are supposed to get 100 exp, which is to be shared between 2 heroes of level 2 and 3, they will each receive 50*70% = 35 and 50*62% = 31 respectively. Which is worse than had only one of them command the creeping ( 100*70% = 70 or 100*62 = 62 ). 

That is why, you creep with just one hero, if heroes are of different levels.

Source: http://classic.battle.net/war3/basics/heroes.shtml

Edit:
"commands" ( it is not defined in the page ), I think means, that the hero is actively engaged in combat along with unit in question. This unit can be in a defined radius of the hero. IIRC, that radius is 600, but I don't have sources for that.