One simplification is to set
\begin{align}
a &= \text{xPos}_2 - \text{xPos}_1, \\
b &= \text{xVel}_2 - \text{xVel}_1, \\
c &= \text{yPos}_2 - \text{yPos}_1, \\
d &= \text{yVel}_2 - \text{yVel}_1.
\end{align}
The vector of displacement from object $1$ to object $2$ at time $t$
is $(a + bt, c + dt)$, and the distance is
$\sqrt{(a + bt)^2 + (c + dt)^2}$.
Your function $f(t)$ becomes
$$
f(t) = (a + bt)^2 + (c + dt)^2 = (b^2 + d^2)t^2 + 2(ab + cd)t + (a^2 + c^2).
$$
In effect, what this does is to convert all your coordinates to the frame of
reference of one of the two objects.
The object whose frame of reference you choose is always at the point
$(0,0)$ in that frame of reference, so all you have to track is the
relative position of the second object, which travels along a straight
line at constant speed.
Now it should be clear that $f(t)$ is the quadratic function
$$ f(t) = At^2 + Bt + C \tag1$$
where $A = b^2 + d^2$, $B = 2(ab + cd)$, and $C = a^2 + c^2$.
In the exceptional case where $b=d=0$, there is no relative motion,
and $f(t)$ remains a constant $a^2 + c^2$. In any other case,
you can find the exact minimum using derivatives, or simply recall
the formula for the vertex of a parabola in this form, which tells us
that the minimum occurs at
$$
t_{\min} = -\frac{B}{2A} = -\frac{ab + cd}{b^2 + d^2}.
$$
If you plug in known values of $\text{xPos}_1$, $\text{xPos}_2$, etc.,
this gives an exact solution for $t_{\min}$, which
you can plug into equation $(1)$ to get the minimum distance
without any guesswork or approximation.
Note that if you replaced $b_x$, $d_x$, $b_y$, and $d_y$
in your version of $f(t)$ with their equal multiples of $t$
(that is, do not replace expressions such as $t \cdot \text{xVel}_1$
with something "simpler"),
expanded all the products, and combined terms with the same powers of $t$,
you would eventually reduce $f(t)$ to something in the form
$ f(t) = At^2 + Bt + C$ where $A$, $B$, and $C$ came out to the same
values in terms of $\text{xPos}_1$, $\text{xPos}_2$, etc.,
as in the calculations above. It would just take more
manipulation do to so.
Best Answer
The shortest line joining line 1 and line 2 is perpendicular to each of them, so has direction $(1,2,3) \times (0,0,1) = (2,-1,0)$.
Make this a unit vector, $\mathbf{u} = (\frac{2}{\sqrt 5},-\frac{1}{\sqrt 5}, 0)$.
Take any point $\mathbf{p}_1$ on line 1, and any point $\mathbf{p}_2$ on line 2; in this case, the obvious choices are $\mathbf{p}_1 = (1,0,-1)$ and $\mathbf{p}_2 = (-1,1,0)$. Let $\mathbf{v} = \mathbf{p}_1-\mathbf{p}_2 = (2,-1,-1)$.
Now the distance between the lines is just $|\mathbf{u}.\mathbf{v}| = \sqrt 5$.