Central American nations have reached an agreement, to allow several thousand Cuban refugees stranded in Costa Rica to continue their journey towards the US.