Maybe this will give you some idea:
1. Have a look at contactform module
2. On this file : modules/contactform/contactform.php have a look at this function : sendMessage
3. Notice the variable {order_name} and how is it assigned using "$order->getUniqReference()"
If you want to get the ID (not reference, but integer id), please refer to getUniqReference() and create a function similar to it that returns the id instead.
See classes/order/Order.php :: getIdOrderProduct(customer, product) for example.
I hope it makes sense for you?
Good luck!