Autocomplete field - fill the selected id into another form element (eg. hidden field)
I've found solution, so I'll share it with others:

Both options in the question were correct. I just expected that the new value of hidden field will be visible through "see source code" which it's not. When I check the $form_state['values']['geonameid'] it is filled correctly.

The complete solution:

1) In Drupal.jsAC.prototype.found I've filled the 'autocompleteValue' with value instead of key, and added new data 'autocompleteKey' which I've filled with key, surprisingly :)

2) In Drupal.jsAC.prototype.hidePopup just added $('input[id="search-geoname-id"]').val($(this.selected).data('autocompleteKey'));

Hope this helps to someone in future.

P.S. I know modifying core functions is not the cleanest way to do things, but it works.