Serial port usage in code
According to sources at c:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial* (on Windows platform), you can use pointer to Stream class (because Serials are inherited from Stream).
So, your function could look like this:
void writeToSerial(bool useSerial1)
{
   Stream* serialPortObject;

   if (useSerial1)
   {
      serialPortObject = &amp;Serial1;
   }
   else
   {
      serialPortObject = &amp;Serial2;
   }

   serialPortObject-&gt;write(&quot;test123&quot;);
}