Answer
In the Name of Allah, Most Gracious, Most Merciful.
All praise and thanks are due to Allah, and peace and blessings be upon His Messenger.
In this fatwa:
Whoever has not prayed the Maghrib until the call for Isha prayer is made can either join the Isha congregational prayer with the intention of Maghrib or pray the Isha prayer with the Imam, then make up the Maghrib prayer after that without praying the Isha prayer again.
Answering your question, The Fatwa Center at Islamweb, states:
Whoever has not prayed Maghrib until the call for the Isha prayer is made can do one of the following:
- Join the Isha congregational prayer with the intention of Maghrib. When the third rak`ah (unit) is finished, he can make the tashahhud (the prayer said while seated) and then say the tasleem (i.e., saying ‘As-salamu Alaykum’ at the end) to end the prayer, then he can stand up to join the last rak`ah with the Imam, or he can remain sitting after the tashahhud until the Imam finishes the prayer and say the salam at the same time with the Imam.
- Pray the Isha prayer with the Imam, then make up the Maghrib prayer after that without praying the Isha prayer again.
Whichever of the above two possibilities he chooses to do, it would be correct according to the opinions of the scholars.
Almighty Allah knows best.
Source: http://www.islamweb.net