Well the theory behind it is basically the msgid is basically the ID of the message you have replied to.
So lets give this an example
You wrote me a message with ID: 5 the msgid would be either 0 or -1 to signify that its just an ordinary message.
Now then I Reply to that message so I send the message with an ID: 6 and MSGID: 5.
From that you may want to reply with ID: 7 and MSGID: 6 and so on and so on.
The original Idea if you wanted all the messages displayed would be to use msgid has the grouping field of the actual original ID then from there order by the time ascending, however with this process its more or less grouping so you will see all previous messages instead of just the previous one.
An example of this method is this
You send a message with ID: 5 msgid: 0 | -1, I then reply to that with ID: 6 msgid: 5 you reply to that message with ID: 7 msgid: 5 as you can see both replies are grouped by the original ID of 5. And from here its ordered by the time.